package com.lb.shopguide.ui.dialog;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lb.shopguide.R;


/**
 * 分享界面dialog
 *
 * @author zk
 */
public class DialogShare extends DialogFragment implements View.OnClickListener {

    private TextView tvTitle;
    private LinearLayout layoutTitle;
    private LinearLayout layoutWeixin;
    private LinearLayout layoutWeixinCircle;

    private OnSharePlatformClick mListener;

    public static DialogShare getDialogShare() {
        DialogShare dialogShare = new DialogShare();
        return dialogShare;
    }

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setStyle(STYLE_NO_TITLE, R.style.dialog_bottom);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View mFragmentView = inflater.inflate(R.layout.dialog_share, container, false);
        layoutWeixin = mFragmentView.findViewById(R.id.ly_share_weichat);
        layoutWeixinCircle = mFragmentView.findViewById(R.id.ly_share_weichat_circle);

        setDialogPosition();
        layoutWeixin.setOnClickListener(this);
        layoutWeixinCircle.setOnClickListener(this);
        return mFragmentView;
    }


    private void setDialogPosition() {
        Window window = getDialog().getWindow();
        window.setGravity(Gravity.BOTTOM | Gravity.FILL_HORIZONTAL);
    }

    @Override
    public void show(FragmentManager manager, String tag) {
        FragmentTransaction ft = manager.beginTransaction();
        ft.add(this, tag);
        ft.commitAllowingStateLoss();
    }

    public void setOnPlatformClickListener(OnSharePlatformClick lis) {
        mListener = lis;
    }

    @Override
    public void onClick(View v) {
        final int id = v.getId();
        if (mListener != null) {
            mListener.onPlatformClick(id);
        }
    }

    public interface OnSharePlatformClick {
        void onPlatformClick(int id);
    }


}
